﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.BackgroundColor = ConsoleColor.DarkBlue;
            Console.Clear();
            Console.ForegroundColor = ConsoleColor.Yellow;
            //Console.BackgroundColor = ConsoleColor.DarkGreen;

            string[] array = { "Add", "Edit", "Delete", "List", "Exit" };
            int i;
            int j = 10;

            int index = 0;

            do
            {
               
               for (i = 0; i < array.Length; i++)
                {
                    if (i != index)
                    {
                        j = Menubutton(array, i, j, ConsoleColor.DarkGreen);
                    }

                    else
                    {
                        j = Menubutton(array, i, j, ConsoleColor.DarkGray);
                    }
                }
               bool b = MuveKursor(ref j, ref index);
              
                if (b == false)
               {
                   break;
               }

            }

            while (true);
            
        }

        private static bool MuveKursor(ref int j, ref int index)
        {
            ConsoleKeyInfo key = Console.ReadKey();

            if (key.Key == ConsoleKey.DownArrow && index < 4)
            {
                index++;
                j = 10;
            }
            if (key.Key == ConsoleKey.UpArrow && index > 0)
            {
                index--;
                j = 10;
            }
            if (key.Key == ConsoleKey.Enter)
            {
                Console.BackgroundColor = ConsoleColor.Black;
                Console.ForegroundColor = ConsoleColor.White;
                Console.Clear();
                Console.SetCursorPosition(40, 10);
                Console.WriteLine("Add");
                return false;
            }
            
            else
            {
                j = 10;
            }

            return true;
        }



        private static int Menubutton(string[] array, int i, int j, ConsoleColor color)
        {
            Console.BackgroundColor = color;

            int n = 20 / 2;
            string str = array[i];
            int l = str.Length;
            int Rn = str.Length / 2;
            int fst = 0;
            if (str.Length % 2 > 0)
            {
                fst = n - Rn - 1;
            }
            else
            {
                fst = n - Rn;
            }
            int fnsh = n - Rn;
            
            Console.SetCursorPosition(28, j);
            for (int k = 0; k < 20; k++)
            {
                Console.Write(" ");

            }
            j++;
            Console.SetCursorPosition(28, j);
            for (int k = 0; k < fst; k++)
            {

                Console.Write(" ");
            }

            Console.Write("{0}", array[i]);

            for (int k = 0; k < fnsh; k++)
            {
                Console.Write(" ");

            }
            j++;
            Console.SetCursorPosition(28, j);
            for (int k = 0; k < 20; k++)
            {
                Console.Write(" ");

            }

            j++;
            return j;
        }
    }
}